<?php
	/**
	 * 
	 * @param $tpl_name
	 */
	function agora_get_template_filepath($tpl_name) {
		// some imports
		jimport('joomla.filesystem.file');
		jimport('joomla.filesystem.folder');
		// our paths
		$overridePath = JPATH_THEMES . DS . JFactory::getApplication()->getTemplate() . DS . 'html' . DS . 'com_agora';
		$defaultPath  = JPATH_ROOT . DS . 'components' . DS . 'com_agora' . DS . 'template';
		// load the appropriate template
		if (JFolder::exists($overridePath)) {
			if (JFile::exists($overridePath . DS . $tpl_name)) {
				return $overridePath . DS . $tpl_name;
			}
		}
		if (JFile::exists($defaultPath . DS . $tpl_name)) {
			return $defaultPath . DS . $tpl_name;
		}
		// uh-oh... what to do now?
		return false;
	}
	
	/**
	 * 
	 * 
	 * @param $tpl_name
	 * @param $tpl_source
	 * @param $smarty_obj
	 * @return bool
	 */
	function smarty_resource_agora_source($tpl_name, &$tpl_source, &$smarty_obj) {
		jimport('joomla.filesystem.file');
		$file = agora_get_template_filepath($tpl_name);
		if ($file && JFile::exists($file)) {
			$tpl_source = JFile::read($file);
			return true;
		}
		// uh-oh... what to do now?
		return false;
	}
	
	/**
	 * 
	 * 
	 * @param $tpl_name
	 * @param $tpl_timestamp
	 * @param $smarty_obj
	 */
	function smarty_resource_agora_timestamp($tpl_name, &$tpl_timestamp, &$smarty_obj) {
		jimport('joomla.filesystem.file');
		$file = agora_get_template_filepath($tpl_name);
		if ($file && JFile::exists($file)) {
			$tpl_timestamp = @filemtime($file);
		}
		if (!$tpl_timestamp) {
			$tpl_timestamp = time();
		}
		return true;
	}
	
	/**
	 * basically a dummy function - assume secure
	 * 
	 * @param $tpl_name
	 * @param $smarty_obj
	 */
	function smarty_resource_agora_secure($tpl_name, &$smarty_obj) {
		return true;
	}
	
	function smarty_resource_agora_trusted($tpl_name, &$smarty_obj) {
		// not used for templates
	}

